package com.chixing.service.impl;

import com.chixing.mapper.PianhaoMapper;
import com.chixing.pojo.Pianhao;
import com.chixing.pojo.PianhaoExample;
import com.chixing.service.PianhaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PianhaoServiceImpl implements PianhaoService {
    @Autowired
    private PianhaoMapper pianhaoMapper;

    @Override
    public void pianhao2Update(Integer memberId, Integer carId, Float value) {
        PianhaoExample example = new PianhaoExample();
        example.createCriteria().andMenberIdEqualTo(memberId).andCarIdEqualTo(carId);
        List<Pianhao> list = pianhaoMapper.selectByExample(example);
        if(list.size()>0){
            System.out.println("已经存在，进行更新值");
            Pianhao pianhao = list.get(0);
            pianhao.setPianhaoScore(value);
            pianhao.setPianhaoTime(new Date());
            pianhaoMapper.updateByPrimaryKey(pianhao);
        }else {
            System.out.println("不存在，不用更新值");
            Pianhao pianhao = new Pianhao();
            pianhao.setMenberId(memberId);
            pianhao.setCarId(carId);
            pianhao.setPianhaoScore(value);
            pianhao.setPianhaoTime(new Date());
            pianhaoMapper.insert(pianhao);
        }
    }
}
